package com.smag.web.controller.echarts.cone;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.smag.echarts.domain.EchartsConeType;
import com.smag.echarts.service.IEchartsConeTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.common.core.page.TableDataInfo;

/**
 * 粮食种类Controller
 * 
 * @author ruoyi
 * @date 2023-04-26
 */
@RestController("coneTypeController")
@RequestMapping("/echarts/cone/type")
public class TypeController extends BaseController
{
    @Autowired
    private IEchartsConeTypeService echartsConeTypeService;

    @RequestMapping("/firstList")
    public AjaxResult firstList() {
        return success(echartsConeTypeService.firstList());
    }

    /**
     * 查询粮食种类列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsConeType echartsConeType)
    {
        startPage();
        List<EchartsConeType> list = echartsConeTypeService.selectEchartsConeTypeList(echartsConeType);
        return getDataTable(list);
    }

    /**
     * 导出粮食种类列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "粮食种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsConeType echartsConeType)
    {
        List<EchartsConeType> list = echartsConeTypeService.selectEchartsConeTypeList(echartsConeType);
        ExcelUtil<EchartsConeType> util = new ExcelUtil<EchartsConeType>(EchartsConeType.class);
        util.exportExcel(response, list, "粮食种类数据");
    }

    /**
     * 获取粮食种类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(echartsConeTypeService.selectEchartsConeTypeById(id));
    }

    /**
     * 新增粮食种类
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "粮食种类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsConeType echartsConeType)
    {
        return toAjax(echartsConeTypeService.insertEchartsConeType(echartsConeType));
    }

    /**
     * 修改粮食种类
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "粮食种类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsConeType echartsConeType)
    {
        return toAjax(echartsConeTypeService.updateEchartsConeType(echartsConeType));
    }

    /**
     * 删除粮食种类
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "粮食种类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(echartsConeTypeService.deleteEchartsConeTypeByIds(ids));
    }
}
